using System;
using System.Diagnostics;
using System.Reactive.Concurrency;
using ReactiveUI;

namespace Avalonia.MusicStore.Commons;

public class GlobalObservableExceptionHandler : IObserver<Exception>
{
    public void OnNext(Exception value)
    {
        // if (Debugger.IsAttached) Debugger.Break();

        RxApp.MainThreadScheduler.Schedule(() => 
        { 
            Console.WriteLine("系统错误 OnNext：" + value.Message);
        }) ;
    }

    public void OnError(Exception error)
    {
        // if (Debugger.IsAttached) Debugger.Break();

        RxApp.MainThreadScheduler.Schedule(() => { Console.WriteLine("系统错误 OnError：" + error.Message); });
    }

    public void OnCompleted()
    {
        // if (Debugger.IsAttached) Debugger.Break();
        RxApp.MainThreadScheduler.Schedule(() => { Console.WriteLine("系统错误处理完成 OnCompleted"); });
    }
}